package edu.ptu.springboot04.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.ptu.springboot04.domain.entity.Collect;
import edu.ptu.springboot04.domain.entity.Product;
import edu.ptu.springboot04.domain.vo.ProductVo;
import edu.ptu.springboot04.mapper.CollectMapper;
import edu.ptu.springboot04.mapper.ProductMapper;
import edu.ptu.springboot04.service.IProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @BelongsProject: springboot04
 * @BelongsPackage: edu.ptu.springboot04.service.impl
 * @Author: HYJ
 * @CreateTime: 2025-03-20  21:30
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Resource
    private ProductMapper productMapper;

    @Resource
    private CollectMapper collectMapper;

    //根据商品id获取商品信息
    @Override
    public ProductVo getProductVoById(Long productId, Long userId) {
        ProductVo productVo = productMapper.selectProductVoById(productId);

        Collect collect = collectMapper.isCollected(productId, userId);

        productVo.setIsCollected(collect == null ? 0 : 1);
        return productVo;
    }
}
